package leetcode101.ch2;

import java.util.Arrays;
import java.util.Comparator;

public class MinArrowsToBurstBallons {
    public int findMinArrowShots(int[][] points) {
//        Arrays.sort(points, (p1, p2) -> p1[1] -p2[1]);
        //上面那个写法会越界
        Arrays.sort(points, Comparator.comparingInt(p -> p[1]));
        int count = 1;
        int rightIdx = points[0][1];
        for (int i = 1; i < points.length ; i++) {
            if (points[i][0] > rightIdx) {
                rightIdx = points[i][1];
                count++;
            }
        }
        return count;
    }
}
